using System.Linq;
using WorkbookDesigner.Addons.SpreadsheetEditor.Presenter;

namespace WorkbookDesigner.Addons.SpreadsheetEditor.Model
{
    public sealed class ActionEditPrompt : ActionModel
    {
        public ActionEditPrompt(PromptModel template, PromptModel newTemplate) : base(OpType.Edit)
        {
            Template = template;
            NewTemplate = newTemplate;
        }
        public PromptModel NewTemplate { get; }
        public override void Execute(IMission m)
        {
            var list = m.GetPromptList(false);
            var plist = list.Where(x => x.Name == Template.Name && x.Row != null);
            foreach (var p in plist)
            {
                NewTemplate.AddTo(p.Row);
            }
        }
    }
}